package io.renren.modules.sell.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.sell.dao.ProductCategoryDao;
import io.renren.modules.sell.dao.ProductDao;
import io.renren.modules.sell.entity.OrderMaster;
import io.renren.modules.sell.entity.ProductCategory;
import io.renren.modules.sell.entity.ProductInfo;
import io.renren.modules.sell.service.ProducetCategoryService;
import io.renren.modules.sell.service.ProductService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ProductCategoryImpl
 * @Author mengjiafeng
 * @Date 2020/4/11 14:22
 **/
@Service
public class ProductImpl extends ServiceImpl<ProductDao, ProductInfo> implements ProductService {

    @Override
    public PageUtils queryPageByUserId(Map<String, Object> params) {
        Long createUserId = (Long) params.get("createUserId");
        String categoryType = (String) params.get("categoryType");
        IPage<ProductInfo> page=null;
//        if (categoryType!=null){
//            Integer categortId = Integer.valueOf(categoryType);
//            page = this.page(
//                    new Query<ProductInfo>().getPage(params),
//                    new QueryWrapper<ProductInfo>()
//                            .eq(createUserId != null, "seller_id", createUserId)
//                            .eq(categortId!=null,"category_type",categortId)
//            );
//        }
//        else {
            page = this.page(
                    new Query<ProductInfo>().getPage(params),
                    new QueryWrapper<ProductInfo>()
                            .eq(createUserId != null, "seller_id", createUserId)
                            .eq(StringUtils.isNotBlank(categoryType),"category_type",categoryType)
            );
//        }

        return new PageUtils(page);
    }

    @Override
    public void deleteBatch(Integer[] productIds) {
        this.removeByIds(Arrays.asList(productIds));
    }
}
